<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>带参数的过滤器</title>
</head>
<body>

<div id="app">
  {{date}}
  <div>{{date | format('yyyy-MM-dd')}}</div>
</div>

<script src="../lib/vue.js"></script>
<script>
  // 过滤器调用时传的传输在形参的第二个位置开始接收
  Vue.filter('format', function (val, fmt) {
    let fmtDate = '';
    let year = val.getFullYear();
    let month = val.getMonth() + 1;
    let date = val.getDate();

    if (fmt === 'yyyy-MM-dd') {
      return fmtDate = year + '-' + month + '-' + date;
    }
  })

  let vm = new Vue({
    el: '#app',
    data: {
      date: new Date()
    }
  })
</script>

</body>
</html>